"""
@Time : 2021/9/15 21:17 
@Author : 常雷
@File : t_15setdefauit.py 
@Software: PyCharm
"""
'''
题目:
    将列表内的元素,根据位数合并成字典
例:
    lst = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 4294967296]
    
    输出:
        {
            1:[1, 2, 4, 8]
            2:[16, 32, 64]
            3:[128, 256, 512]
            4:[1024, 2048, 4096, 8192]
            5:[16384, 32768, 65536]
            6:[4294967296]
        }
'''
dic = {}    # 存放最终结果
lst = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 4294967296]

for itme in lst:
    it_s = str(itme)
    if len(it_s) < 6:
        dic.setdefault(len(it_s), []).append(itme)
        # 有则查询, 无则先创建再查询
    else:
        dic.setdefault(6, []).append(itme)

print(dic)